<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>区域编辑</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/ui.css" rel="stylesheet">
    <link href="css/layui.css" rel="stylesheet">
    <link href="css/control.css" rel="stylesheet">
    <style>
        #body {
            width: 100%;
            max-height: 100%;
            overflow-y: scroll;
            overflow-x: hidden;
        }

        .articleImg {
            /* width: 100%; */
            /* height: auto !important; */
            max-width: 100px;
        }

        th,
        td {
            text-align: center;
        }
        .textAreaBlock {
            margin-left: 130px;
            min-height: 36px;
        }
        .form_item_align_left {
            text-align: left;
        }
        .from_item_align_center {
            text-align: center;
        }

    </style>
</head>

<body class="gray-bg animated fadeInRight">
    <div id="body">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">

                            <div id="content">

                                <!--<fieldset style="margin-top: 20px">
                                    <legend>基础信息</legend>
                                </fieldset>-->

                                <div class="layui-inline layui-form">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">项目名称</label>
                                        <div class="layui-input-inline">
                                            <select id="project">
                                                <!--<option value="0" selected="">C20</option>
                                                <option value="1" >C30</option>
                                                <option value="2" >C40</option>
                                                <option value="3" >C50</option>
                                                <option value="4" >C60</option>
                                                <option value="5" >C70</option>
                                                <option value="6" >C80</option>-->
                                            </select>
                                        </div>
                                    </div>

                                </div>
                                <div class="layui-form-item form_item_align_left">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">区域名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text"  id="regoinName" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                </div>
                                <!--<div class="layui-form-item form_item_align_left">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">操作人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly="readonly" id="operator" lay-verify="required|number" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                </div>-->



                            </div>
                            <div class="from_item_align_center">
                                <button class="btn btn-info layui-btn-normal regoin-edit" style="margin-left: 20px">确&nbsp;&nbsp;&nbsp;&nbsp;定</button>
                                <button  class="btn btn-info layui-btn-normal" onclick="backForwardListen()" style="margin-left: 20px">返&nbsp;&nbsp;&nbsp;&nbsp;回</button>

                            </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/work/common.js"></script>
    <script src="js/plugins/laydate/laydate.js"></script>
    <script src="js/plugins/layer/layer.min.js"></script>
    <script src="js/plugins/layer/layer.js"></script>
    <script src="js/layui.js"></script>
    <!-- 自定义js -->
    <script src="js/content.js"></script>
    <script>
        var form;
        layui.use(['form'], function () {
            form = layui.form;

        })
        var regoinId = getStorage("regoinId");
        var regoinName = getStorage("regoinName");
        $(document).ready(function () {
            $("#regoinName").attr("value", regoinName);
            setTimeout(function () {
                initPileProject();
            },200)
        });


        function initPileProject() {
            ajax({
                url: "pile/showPileProject",
                type: "POST",
                dataType: "json",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data: {},
                timeout: 10000,
                contentType: "application/json;charset=utf-8",
                error: function (xhr, type) {
                    layer.msg("服务器异常，请稍后重试！", {time: 2000})
                },
                successx: function (data) {
                    if (data.success == true) {
                        setProject(data.data);
                    } else {
                        layer.msg(data.message, {time: 1000})
                    }
                }
            });

        }

        function setProject(data) {
            if (data == null) {
                return;
            }
            $("#project").html("");
            var optionHtml = "";
            for (var i = 0; i < data.length ; i++) {
                var option = '<option value="'+data[i].id+'">'+data[i].name+'</option>';
                optionHtml += option;
            }
            $("#project").html(optionHtml);
            form.render();
        }


        $(".regoin-edit").click(function () {
            var regoinName = $("#regoinName").val();
            var projectId = $("#project").val();
            ajax({
                url: "pile/createRegion",
                type: "POST",
                dataType: 'json',
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data: JSON.stringify({id: regoinId, name: regoinName, pileProjectId: projectId}),
                timeout: 10000,
                contentType: "application/json;charset=utf-8",
                error: function (xhr, type) {},
                successx: function (data) {
                    if (data.success == true) {
                        layer.msg(data.message,{icon:1});
                        setTimeout(function(){
                            window.location.href = "regoinlist.html";
                        },1800)
                    } else {
                        layer.msg(data.message,{time:1000})
                    }
                },
            });

        });




    </script>

</body>

</html>